#!/bin/bash -e

echo "Usage: [docker_version=] $0"
echo "Example: [docker_version=18.06.3] $0"

yum install -y yum-utils device-mapper-persistent-data lvm2

#yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast

if [ -z "${docker_version}" ]; then
    yum install -y docker-ce
else
    yum install -y "docker-ce-${docker_version}"
fi

mkdir /etc/docker
echo "{\
  \"registry-mirrors\": [\
    \"https://dockerhub.azk8s.cn\",\
    \"https://hub-mirror.c.163.com\"\
  ]\
}" > /etc/docker/daemon.json

# disable firewall
setenforce 0 && sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
systemctl stop firewalld.service && systemctl disable firewalld.service

systemctl start docker
systemctl enable docker
